home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
ubppmpqs.zip
/
ppmp4a.asm
< prev
next >
Wrap
Assembly Source File
|
1993-04-16
|
19KB
|
1,317 lines
;PPMP4a.ASM 2.0
; MACHINE LANGUAGE SUBROUTINES
; FOR PPMPQS
; 1991/92 by YUJI KIDA
;
.386P
code segment use16
assume cs:code,ds:code
INCLUDE UBP.MAC
include ppmp.h
inactivesteplog equ 9
org 100h
start:
;branch
MOV_AX AR0 ;ARRAY[0] is the command
MOV BX,OFFSET CMD_TBL
SHL AX,1
ADD BX,AX
JMP CS:[BX]
CMD_TBL:
dw INITIALIZE,GETPRIME,STORE_DATA,SETACTIVE,COUNTCOLUMN
dw DELETEROW,GAUSS1,GAUSS2,CUTEXCESSROW,MAKERFB,GETMEMORYSIZE
even
maxlen dw 0
P_OFF dw ?
P_SEG dw ?
primeadrnow dd ?
W_OFF dw ?
W_SEG dw ?
Drv_OFF dw ?
Drv_SEG dw ?
FBsize dw ?
primes dw ?
rowstotal dw ?
rowsnow dw ?
columnsweight0 dw ?
excessrows dw ?
heavycolweight dw ?
offnow dw ?
primenow dw ?
count0 dw ?
count1 dw ?
count2 dw ?
inactivenow dw ?
inactivenext dw ?
inactivecount dw ?
primehandle dw ?
decomhandle dw ?
histhandle dw ?
ptrbuffer2 dw ?
ptrbuffer3 dw ?
length1 dw ?
length2 dw ?
spmem dw ?
didsomesw dw 0
align 4
pointernow dd ?
datanow dd ?
columncount dd ?
counterbase dd ?
pointerbase dd ?
database dd ?
activeflgbase dd ?
;
; get memory size
;
;command#=10
getmemorysize:
mov esi,pmodeworkadr-4
mov eax,19510701h
mov edx,00000400h ;1Kbytes
mov cx,31*1024 ;max 31Mbytes
checkmemory100:
inc eax
add esi,edx
mov fs:[esi],eax
cmp eax,fs:[esi]
loope checkmemory100
mov esi,pmodeworkadr-4 ;chack again for cache memory
mov eax,19510701h
mov edx,00000400h ;1Kbytes
mov cx,31*1024 ;max 31Mbytes
checkmemory110:
inc eax
add esi,edx
cmp eax,fs:[esi]
loope checkmemory110
mov eax,esi
sub eax,edx
sub eax,pmodeworkadr-4
shr eax,10 ;Kbytes
mov bx,AR0
mov cs:[bx],ax
retf
;
; make reduced FactorBase file
; and revived Row number file
;
;command#=9
RFBhandle dw ?
RFBFILENAME db 'PPMPRFB.PPM',0
ROWShandle dw ?
ROWSFILENAME db 'PPMPROWS.PPM',0
makeRFB:
mov ax,cs
mov ds,ax
mov es,ax
mov ah,3eh ;close history
mov bx,[histhandle]
or bx,bx
jz short makeRFB0
int 21h
makeRFB0:
mov dx,offset RFBFILENAME
mov ah,3ch ;create handle
mov cx,0
int 21h
jc diskerror
mov [RFBhandle],ax
xor dx,dx ;counter
mov ebx,[activeflgbase]
mov cx,[FBsize]
makeRFB10:
push ebx
push cx
mov ax,0ffffh ;non use mark
cmp byte ptr fs:[ebx],1
jne short makeRFB20
mov ax,dx
inc dx
makeRFB20:
push dx
mov bx,offset BUFFER
mov [bx],ax
mov dx,bx
mov cx,2
mov bx,[RFBhandle]
mov ah,40h ;write
int 21h
pop dx
pop cx
pop ebx
jc diskerror
inc ebx
loop makeRFB10
cmp dx,[inactivenow]
jne makeRFBdataerror
push dx ;/*
mov ah,3eh ;close
mov bx,[RFBhandle]
or bx,bx
jz short makeROWS
int 21h
makeROWS:
mov dx,offset ROWSFILENAME
mov ah,3ch ;create handle
mov cx,0
int 21h
jc diskerror
mov [ROWShandle],ax
xor dx,dx ;counter
mov ebx,[pointerbase]
mov cx,[FBsize]
makeROWS10:
test dword ptr fs:[ebx],deletedmark4B
jnz short makeROWS20
push bx
push cx
push dx
mov bx,offset BUFFER
mov ax,[FBsize]
sub ax,cx
mov [bx],ax
mov dx,bx
mov cx,2
mov bx,[ROWShandle]
mov ah,40h ;write
int 21h
jc diskerror
pop dx
pop cx
pop bx
inc dx
makeROWS20:
add ebx,4
loop makeROWS10
pop ax ;*/
cmp ax,dx
jae short makeROWS30
mov ax,dx
makeROWS30:
add ax,matrixunitsize-1
and ax,matrixunitmask
shr ax,1 ;reduced matrix size / 2
makeRFBret:
mov bx,AR0
mov word ptr [bx],ax
mov ah,3eh ;close
mov bx,[RFBhandle]
or bx,bx
jz short makeRFBskip
int 21h
makeRFBskip:
mov ax,ss
mov ds,ax
mov es,ax
retf
makeRFBdiskerror:
mov ax,8001h
jmp makeRFBret
makeRFBdataerror:
mov ax,8002h ;data error
jmp makeRFBret
;
; cut excess rows
;
;command#=8
CUTEXCESSROW:
mov ax,cs
mov ds,ax
mov es,ax
mov [excessrows],0
mov ax,[rowsnow]
mov dx,[FBsize]
add dx,[inactivenow]
sub dx,[columnsweight0]
add dx,8 ;for safety
sub ax,dx
jbe short excessout ;no excess
mov [excessrows],ax
mov cx,ax ;clear buffer
shl cx,1
mov di,offset BUFFER
xor ax,ax
rep stosw
dec ax
stosw ;sentinel
mov cx,[rowstotal]
mov ebx,[pointerbase]
xor dx,dx ;row#
excess10:
push cx
mov esi,fs:[ebx]
test esi,deletedmark4B
jnz short excess20
mov ax,fs:[esi] ;weight
mov di,offset BUFFER
cmp ax,[di]
jb short excess20
call storethisrownumber
excess20:
add ebx,4
inc dx
pop cx
loop excess10
;now delete highest weight rows
mov si,offset BUFFER
mov cx,[excessrows]
excess50:
xor eax,eax
add si,2
lodsw
or ax,ax
jz short excess60
shl eax,2
add eax,[pointerbase]
or dword ptr fs:[eax],deletedmark4B
dec [rowsnow]
excess60:
loop excess50
excessout:
mov ax,[excessrows]
mov bx,AR0
mov [bx],ax
mov ax,ss
mov ds,ax
mov es,ax
retf
storethisrownumber:
push ebx
storethisrow10:
mov ebx,[di+4]
cmp ax,bx
jb short storethisrow50
mov [di],ebx
add di,4
jmp storethisrow10
storethisrow50:
mov [di],ax ;weight
mov [di+2],dx ;row#
pop ebx
ret
;
; GAUSSian elimination using the rows of weight 2
;
;command#=7
GAUSS2:
mov ax,cs
mov ds,ax
mov es,ax
mov [spmem],sp
mov [didsomesw],0
mov ebx,[pointerbase]
mov cx,[rowstotal]
gauss210:
push cx
push ebx
mov esi,fs:[ebx]
test esi,deletedmark4b
jnz short gauss220
mov ax,fs:[esi] ;weight
cmp ax,2
jne short gauss220
or dword ptr fs:[ebx],deletedmark4B
dec [rowsnow]
call setpivotnumber
call gauss2sub
call appendhistory
gauss220:
pop ebx
add ebx,4
pop cx
loop gauss210
mov ax,[didsomesw]
mov bx,AR0
mov [bx],ax
mov ax,ss
mov ds,ax
mov es,ax
retf
gauss2sub:
mov dx,fs:[esi+2] ;dx = pivot less value
mov ax,fs:[esi+4] ;ax = pivot larger value
mov ebx,[pointerbase]
mov cx,[rowstotal]
gauss2submainlp:
push cx ;*
mov esi,fs:[ebx]
test esi,deletedmark4b
jnz short gauss2sub20
mov cx,fs:[esi]
jcxz short gauss2sub20
gauss2sub12:
add esi,2
cmp ax,fs:[esi]
jb short gauss2sub20
je short gauss2sub30
loop gauss2sub12
gauss2sub20:
add ebx,4
pop cx ;*
loop gauss2submainlp
ret
gauss2sub30:
push eax
call replacethis
call memooperation
pop eax
jmp gauss2sub20
replacethis:
mov edi,fs:[ebx] ;top adr
mov ecx,esi
sub ecx,edi
shr cx,1
dec cx ;data# to be checked
jz short replacethisret
replacethislp:
mov ax,fs:[esi-2]
cmp ax,dx
jb short replacethisret
je short cutthis2
mov fs:[esi],ax
sub esi,2
loop replacethislp
replacethisret:
mov fs:[esi],dx
replacethisret2:
ret
cutthis2:
mov ax,fs:[edi] ;weight
mov cx,ax
sub ax,2
mov fs:[edi],ax
jz replacethisret2
mov eax,esi
sub eax,edi
shr ax,1
sub cx,ax
jz replacethisret2
cutthis2lp:
add esi,2
mov ax,fs:[esi]
mov fs:[esi-4],ax
loop cutthis2lp
jmp replacethisret2
;
; GAUSSian elimination using the rows of weight 1
;
;command#=6
GAUSS1:
mov ax,cs
mov ds,ax
mov es,ax
mov [spmem],sp
mov [didsomesw],0
gauss1mainlp:
mov ebx,[pointerbase]
mov cx,[rowstotal]
gauss110:
push cx
push ebx
mov esi,fs:[ebx]
test esi,deletedmark4b
jnz short gauss120
mov ax,fs:[esi] ;weight
cmp ax,1
jne short gauss120
gaussweight1:
or dword ptr fs:[ebx],deletedmark4B
dec [rowsnow]
call setpivotnumber
call gauss1sub
call appendhistory
gauss120:
pop ebx
add ebx,4
pop cx
loop gauss110
mov ax,[didsomesw]
mov bx,AR0
mov [bx],ax
gauss1out:
mov ax,ss
mov ds,ax
mov es,ax
retf
appendhistory:
mov dx,offset BUFFER
mov cx,[ptrbuffer2]
sub cx,dx
jbe short historyret
mov bx,[histhandle]
mov ah,40h ;write
int 21h
jc gauss1diskerror
mov [didsomesw],1
historyret:
ret
setpivotnumber:
mov eax,ebx ;pivot element number
sub eax,[pointerbase]
shr eax,2
mov di,offset BUFFER0
stosw
mov [ptrbuffer2],di
ret
gauss1sub:
mov ax,fs:[esi+2] ;ax = pivot value
mov ebx,[pointerbase]
mov cx,[rowstotal]
gauss1submainlp:
push cx ;*
mov esi,fs:[ebx]
test esi,dele